import util from '@/libs/util';

export default {
    name: 'exportable-table',
    data () {
        return {
            columns: [{
                title: '姓名',
                key: 'student_name',
                render:(h,params)=>{
                    return h("a",{
                        on:{
                            click: () => {
                               this.detailsVisible=true;
                               this.showDetails(params.row.id);
                            }
                        }
                    },params.row.student_name)
                }
            }, {
                title: '性别',
                key: 'sex'
            }, {
                title: '证件号',
                key: 'cardcode'
            }, {
                title: '出生日期',
                key: 'birthdate'
            }, {
                title: '手机号',
                key: 'parentphone'
            }, {
                title: '家庭电话',
                key: 'parentphone'
            }, {
                title :'家长姓名',
            key :'parentname'
            },{
                title:'就读年级',
                key :'grade_id'
            },{
                title  :'就读学校',
                key  :'school'
            }],
            total: 0,
            pageSize: 10,
            pageIndex: 1,
            dataList:[],
            queryData: {
                billCode: '',
                name: '',
                cardCode: '',
                parentPhone: ''
            },
            detailsVisible:false,
            student:{},
            bill_columns:[
                {
                    title: '预约号',
                    key: 'billcode'
                },{
                    title: '学年',
                    key: 'class_year'
                },{
                    title: '学期',
                    key: 'class_season_name'
                },{
                    title: '班级代码',
                    key: 'class_code'
                },{
                    title: '班级名称',
                    key: 'class_name'
                },{
                    title: '部门',
                    key: 'department_name'
                },{
                    title: '专业',
                    key: 'marjor_name'
                },{
                    title: '课表',
                    key: 'classSchedules',
                    render: function (h, params) {
                        let list = params.row.classSchedules;
                        if (typeof (list) === 'string') {
                            list = JSON.parse(list);
                        }
                        let list_h = [];
                        for (let i in list) {
                            let startTime = list[i].classStartTime;
                            let endTime = list[i].classEndTime;
                            if (startTime) {
                                startTime = startTime.substring(0, 2) + ':' + startTime.substring(2, 4);
                            }
                            if (endTime) {
                                endTime = endTime.substring(0, 2) + ':' + endTime.substring(2, 4);
                            }
                            let fun = h('div', util.convertNumToWeekOfDay(list[i].classType) + ' ' + startTime + '-' + endTime + ' ' + list[i].classRoomName);
                            list_h.push(fun);
                        }
                        return h('span', list_h);
                    }
                },{
                    title: '订单金额(元)',
                    key: 'total_amt'
                },{
                    title: '报名方式',
                    key: 'signType'
                },{
                    title: '报名状态',
                    key: 'status'
                },
            ],
            bill_dataList:[],
        };
    },
    mounted () {
        this.loadList();
    },
    methods: {
        loadList: function () {
            util.ajax.post('/busine/bill/getStudentBills', util.toFormData({
                page: this.pageIndex,
                size: this.pageSize,
                billCode: this.queryData.billCode,
                name: this.queryData.name,
                parentPhone: this.queryData.parentPhone,
                cardCode:this.queryData.cardCode,
            })).then(res => {
                this.dataList = res.data.data.list;
                this.total = res.data.data.total;
            });
        },
        refresh :function() {
            this.queryData= {
                billCode: '',
                name: '',
                cardCode: '',
                parentPhone: ''
            };
            this.loadList();
        },
        showDetails:function (id) {
            util.ajax.post('/busine/bill/getBillByStudentid', util.toFormData({
                studentId:id
            })).then(res => {
                   if(res.data.code==200){
                       let data =res.data.data;
                       this.student=data.student
                       this.bill_dataList=data.bill_list;
                       if(this.student.sex=='MAN'){
                           this.student.sex='男'
                       }else if(this.student.sex=='WOMAN'){
                           this.student.sex='女'
                       }
                   }
            });
        }
    },

};
